package com.zmn.oms.admin.controller.conf.reply.category;

import com.zmn.common.dictionary.GlobalDict;
import com.zmn.oms.model.entity.conf.reply.ReplyCategory;
import com.zmn.oms.model.entity.conf.reply.ReplyCategoryQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 类描述:回访类别列表控制器
 *
 * @author linfeng
 * @since 2020/04/15/14:46
 */
@Controller
@RequestMapping(value = "/conf/reply/category/")
public class ReplyCategoryListController extends ReplyCategoryBaseController {
    private Logger logger = LoggerFactory.getLogger(ReplyCategoryListController.class);

    @RequestMapping(value = "list")
    //@RequiresPermissions("/conf/reply/category/list.action")
    public ModelAndView list(@ModelAttribute ReplyCategoryQuery query) {
        List<ReplyCategory> items = replyCategoryService.listPageByQuery(query);

        ModelAndView mav = new ModelAndView("conf/reply/category/list");
        mav.addObject("vo", query);
        mav.addObject("items", items);

        return mav;
    }

    @RequestMapping(value = "detail")
    //@RequiresPermissions("/conf/reply/category/detail.action")
    public ModelAndView detail(@RequestParam(value = "id", defaultValue = "0") Integer id) {
        ReplyCategory replyCategory;
        if (id > 0) {
            replyCategory = replyCategoryService.findById(id);
        } else {
            replyCategory = new ReplyCategory();
        }

        if (replyCategory.getSort() == null) {
            Integer sort = replyCategoryService.findMaxSort();
            sort = sort == null ? 1 : sort + 1;
            replyCategory.setSort(sort);
        }

        ModelAndView mav = new ModelAndView("conf/reply/category/detail");

        mav.addObject("statuses", GlobalDict.getStatusList(false));
        mav.addObject("vo", id);
        mav.addObject("returnvisitcategory", replyCategory);
        return mav;
    }
}
